//
//  HWVoiceRoomGiftCenterBgCell.swift
//  PlayWithProject
//
//  Created by 王昌健 on 2021/8/27.
//

import UIKit

class HWVoiceRoomGiftCenterBgCell: UICollectionViewCell {
    private var collectionView:UICollectionView!
    let collectionProtocol = HWVoiceRoomGiftCenterBgProtocol()
    var didSelectGift:((_:HWVoiceRoomGiftModel)->())?
    var models:[HWVoiceRoomGiftModel]?{
        didSet {
            collectionProtocol.models = models
            collectionView.reloadData()
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initUI()
        
        initFrame()
        
        addAction()
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
extension HWVoiceRoomGiftCenterBgCell {
    private func initUI() -> Void {
        let layout = UICollectionViewFlowLayout.init()
        layout.itemSize = CGSize.init(width: 83, height: 97)
        layout.minimumLineSpacing = 10
        layout.minimumInteritemSpacing = 4
        layout.sectionInset = .init(top: 10, left: 15, bottom: 0, right: 14)
        layout.scrollDirection = .vertical
        collectionView = UICollectionView.init(frame: .zero, collectionViewLayout: layout)
        collectionView.register(HWVoiceRoomGiftCell.self, forCellWithReuseIdentifier: "HWVoiceRoomGiftCell")
        collectionView.delegate = collectionProtocol
        collectionView.dataSource = collectionProtocol
        collectionView.backgroundColor = UIColor.clear
        addSubview(collectionView)
    }
    
    private func initFrame() -> Void {
        collectionView.snp.makeConstraints { make in
            make.left.top.right.bottom.equalTo(0)
        }
    }
}
extension HWVoiceRoomGiftCenterBgCell {
    func addAction() -> Void {
        collectionProtocol.didSelectRow = {
            mod in
            self.didSelectGift?(mod)
        }
    }
}
